package com.yaorange.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yaorange.entity.User;
import com.yaorange.mapper.UserMapper;
import com.yaorange.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @description:
 * @company: yaorange
 * @author: CorJ
 * @version: 1.0
 * @create: 2021-11-28 14:25
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public List<User> findAllUser() {
        return userMapper.selectAll();
    }

    @Override
    public PageInfo<User> pageUser(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        return new PageInfo<>(userMapper.selectAll());
    }

    @Override
    public boolean addUser(User user) {
        try {
            userMapper.insertUser(user);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }

    }

    @Override
    public User getUserByName(String loginName) {
        return userMapper.selectByLoginName(loginName);
    }

    @Override
    public User getUserById(Integer id) {
        return userMapper.selectUser(id);
    }
}
